
package com.mybatis.plugins;

import org.mybatis.generator.api.IntrospectedColumn;

import org.mybatis.generator.api.IntrospectedTable;

import org.mybatis.generator.api.PluginAdapter;

import org.mybatis.generator.api.dom.java.Interface;

import org.mybatis.generator.api.dom.java.Method;

import org.mybatis.generator.api.dom.java.TopLevelClass;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.List;

import java.util.Properties;

import static org.mybatis.generator.internal.util.StringUtility.isTrue;

/**

 * @author: xuKai

 * @date: 2024/3/6 12:31

 * @description:

 */

public class LombokPlugin extends PluginAdapter {

    private boolean useLombok;

    public LombokPlugin(){}

    @Override

    public void setProperties(Properties properties) {

        super.setProperties(properties);

        useLombok = isTrue(properties.getProperty("useLombok")); //$NON-NLS-1$

    }

    @Override

    public boolean validate(List<String> list) {

        return useLombok;

    }

    public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {

        topLevelClass.addImportedType("lombok.Getter");

        topLevelClass.addImportedType("lombok.Setter");

        topLevelClass.addImportedType("lombok.ToString");

        topLevelClass.addAnnotation("@Setter");

        topLevelClass.addAnnotation("@Getter");

        topLevelClass.addAnnotation("@ToString");

// topLevelClass.addSuperInterface(new FullyQualifiedJavaType("java.io.Serializable"));

        return true;

    }

    public boolean clientGenerated(Interface anInterface, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {

        anInterface.addJavaDocLine("/**");

        anInterface.addJavaDocLine(" * @author xuKai");

        anInterface.addJavaDocLine(" * @date " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));

        anInterface.addJavaDocLine(" */");

        return true;

    }

//不生成getter

    @Override

    public boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {

        return false;

    }

//不生成getter

    @Override

    public boolean modelGetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {

        return false;

    }

}